package controller;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum UserExisted {
  PrimaryOne("张三1", "123", 1),
  PrimaryTwo("张三2", "123", 1),
  PrimaryThree("张三3", "123", 1),
  JuniorOne("李四1", "123", 2),
  JuniorTwo("李四2", "123", 2),
  JuniorThree("李四3", "123", 2),
  HighOne("王五1", "123", 4),
  HighTwo("王五2", "123", 4),
  HighThree("王五3", "123", 4);

  private String name;
  private String password;
  private int role;

  /**
   * 根据 name 得到枚举的 User
   *
   * @param name username
   * @return UserExisted 存在的user
   */
  public static UserExisted getExistedUser(String name) {
    return Arrays.stream(UserExisted.values())
        .filter(userExisted -> userExisted.getName().equals(name))
        .findFirst()
        .orElse(null);
  }
}
